import Compile from './Compile.js';
import observe from './observe.js';
import Watcher from './Watcher.js';
export default class Vue{
	constructor(options){
		//将传进来的参数设置成自己的参数
		this.$options = options || {};
		this._data = options.data || undefined;
		// 将所有data状态变成可侦测
        observe(this._data);
		//默认数据变成响应式,这里就是生命周期
		this._initData();
		//调用默认watch
		this._initWatch()
		//编译模板
		new Compile(options.el,this);
	};
	_initData(){
		Object.keys(this._data).forEach(key=>{
			Object.defineProperty(this,key,{
				get:()=>{
					return this._data[key]
				},
				set:(newValue)=>{
					this._data[key]=newValue;
					return true
				}
			})
		})
		// console.log('_initData函数');
	}
    _initWatch(){
    	let watch = this.$options.watch ?this.$options.watch:{} ;
    	Object.keys(watch).forEach(key=>{
    		new Watcher(this,key,watch[key])
    	})
		console.log('_initWatch函数')
	}	
}